package com.bst.base.service.impl;

import java.util.List;

import com.bst.base.domain.BaseReportParamFilter;
import com.bst.base.service.IBaseReportParamFilterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bst.base.mapper.BaseReportParamMapper;
import com.bst.base.domain.BaseReportParam;
import com.bst.base.service.IBaseReportParamService;
import com.bst.common.core.text.Convert;

/**
 * 报表参数管理Service业务层处理
 * 
 * @author laoliu
 * @date 2024-10-30
 */
@Service
public class BaseReportParamServiceImpl implements IBaseReportParamService 
{
    @Autowired
    private BaseReportParamMapper baseReportParamMapper;

    /**
     * 查询报表参数管理
     * 
     * @param idReportParam 报表参数管理主键
     * @return 报表参数管理
     */
    @Override
    public BaseReportParam selectBaseReportParamByIdReportParam(Long idReportParam)
    {
        BaseReportParam reportParam = baseReportParamMapper.selectBaseReportParamByIdReportParam(idReportParam);
        BaseReportParamFilter filter = new BaseReportParamFilter();
        filter.setIdReportParam(idReportParam);
        List<BaseReportParamFilter> filters = baseReportParamFilterService.selectBaseReportParamFilterList(filter);
        reportParam.setFilterList(filters);
        return reportParam;
    }

    /**
     * 查询报表参数管理列表
     * 
     * @param baseReportParam 报表参数管理
     * @return 报表参数管理
     */
    @Override
    public List<BaseReportParam> selectBaseReportParamList(BaseReportParam baseReportParam)
    {
        return baseReportParamMapper.selectBaseReportParamList(baseReportParam);
    }

    @Autowired
    IBaseReportParamFilterService baseReportParamFilterService;
    /**
     * 新增报表参数管理
     * 
     * @param baseReportParam 报表参数管理
     * @return 结果
     */
    @Override
    public int insertBaseReportParam(BaseReportParam baseReportParam)
    {
        int i= baseReportParamMapper.insertBaseReportParam(baseReportParam);
        List<BaseReportParamFilter> filters = baseReportParam.getFilterList();
        if(filters!=null && filters.size()>0) {
            for (BaseReportParamFilter filter : filters) {
                filter.setIdReportParam(baseReportParam.getIdReportParam());
                baseReportParamFilterService.insertBaseReportParamFilter(filter);
            }
        }
        return i;
    }

    /**
     * 修改报表参数管理
     * 
     * @param baseReportParam 报表参数管理
     * @return 结果
     */
    @Override
    public int updateBaseReportParam(BaseReportParam baseReportParam)
    {
        return baseReportParamMapper.updateBaseReportParam(baseReportParam);
    }

    /**
     * 批量删除报表参数管理
     * 
     * @param idReportParams 需要删除的报表参数管理主键
     * @return 结果
     */
    @Override
    public int deleteBaseReportParamByIdReportParams(String idReportParams)
    {
        for (String id : Convert.toStrArray(idReportParams)) {
            deleteBaseReportParamByIdReportParam(Long.parseLong(id));
        }
        return 1;
    }

    /**
     * 删除报表参数管理信息
     * 
     * @param idReportParam 报表参数管理主键
     * @return 结果
     */
    @Override
    public int deleteBaseReportParamByIdReportParam(Long idReportParam)
    {
        baseReportParamMapper.deleteBaseReportParamByIdReportParam(idReportParam);
        baseReportParamFilterService.deleteBaseReportParamFilterByIdReportParam(idReportParam);
        return 1;
    }
}
